package org.groupg.practice;

import com.spire.doc.*;
import com.spire.doc.documents.WatermarkLayout;

import java.awt.*;

public class WaterMarkPractice {
    public static void main(String[] args) {
        // 添加文本水印 [citation:7][citation:10]
        Document document = new Document();
        document.loadFromFile("a.doc");
        Section section = document.getSections().get(0);

        TextWatermark txtWatermark = new TextWatermark();
        txtWatermark.setText("内部使用");
        txtWatermark.setFontSize(40);
        txtWatermark.setColor(Color.red);
        txtWatermark.setLayout(WatermarkLayout.Diagonal); // 主要支持对角线布局
        section.getDocument().setWatermark(txtWatermark);
        document.saveToFile("b.doc", FileFormat.Doc);

// 添加图片水印 [citation:7]
//        Document document = new Document();
//        document.loadFromFile("input.docx");
//        PictureWatermark picture = new PictureWatermark();
//        picture.setPicture("watermark.png");
//        picture.setScaling(100); // 设置缩放比例
//        picture.isWashout(false); // 设置是否使用冲蚀效果
//        document.setWatermark(picture);
//        document.saveToFile("output_with_image.docx", FileFormat.Docx);
    }
}
